package com.aidysoft.practice.easypoi.utils.pojo.ImportForMap;

import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl;
import cn.afterturn.easypoi.util.PoiPublicUtil;

import java.util.Map;

public class MapImportHandler extends ExcelDataHandlerDefaultImpl<Map<String, Object>> {

    @Override
    public void setMapValue(Map<String, Object> map, String originKey, Object value) {
        if (value instanceof Double) {
            map.put(getRealKey(originKey), PoiPublicUtil.doubleToString((Double) value));
        } else {
            map.put(getRealKey(originKey), getRealValue(value) != null ? getRealValue(value).toString() : null);
        }
    }

    private String getRealKey(String originKey) {
        if (originKey.equals("学生姓名")) {
            return "name";
        }
        if (originKey.equals("学生性别")) {
            return "sex";
        }
        if (originKey.equals("出生日期")) {
            return "bir";
        }if (originKey.equals("进校日期")) {
            return "entry";
        }
        return originKey;
    }
    private Object getRealValue(Object value) {
        if (value.equals("男生")) {
            return "1";
        }if (value.equals("女生")) {
            return "2";
        }

        return value;
    }

}
